#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->sendBtn->setEnabled(false);
    tcpclient = new QTcpSocket(this);
    connect(tcpclient, &QTcpSocket::connected, this, &Widget::connectToServer);
    connect(tcpclient, &QTcpSocket::readyRead, this, &Widget::readInformation);

}

Widget::~Widget()
{
    delete ui;
}
void Widget::on_connectBtn_clicked() {
    QString ip = ui->lineEditServerIp->text();
    qint16 port = ui->lineEditPort->text().toInt();
    QString portText = ui->lineEditPort->text();

}
void Widget::on_sendBtn_clicked() {

}
void Widget::readInformation() {
    QByteArray tmp = tcpclient->readAll();
    if (!tmp.isEmpty())
    {
        ui->textEditRecv->append(tmp);
    }
}
void Widget::connectToServer() {
    ui->textEditRecv->setText("Successfully established a link with the server");
}